package com.xx.secret.entity;

import lombok.Data;

/**
 * @author ：wangcheng
 * @date 2024/3/13
 **/
@Data
public class Result<T> {

    private static final int SUCCESS_CODE = 200;
    private static final int FAILURE_CODE = 300;
    private static final String SUCCESS_MSG = "success";

    private Integer code;

    private String message;

    private T data;

    public Result() {
        this.code = SUCCESS_CODE;
        this.message = SUCCESS_MSG;
    }

    public Result(T data) {
        this.code = SUCCESS_CODE;
        this.message = SUCCESS_MSG;
        this.data = data;
    }

    public Result(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(data);
    }

    public static <T> Result<T> success() {
        return new Result<>();
    }

    public static Result error(String msg) {
        return new Result(FAILURE_CODE, msg);
    }

    public static Result error() {
        return new Result(FAILURE_CODE, "failure");
    }
}
